'use strict';
const dayjs = require("dayjs");

module.exports = app => {
  const { STRING, INTEGER, DATE } = app.Sequelize;
  
  const Carousels = app.model.define(
    'Carousels',
    {
      id: { type: INTEGER, primaryKey: true, autoIncrement: true },
      title: { type: STRING(100) },
      image_url: { type: STRING(255), allowNull: false },
      sort: { type: INTEGER, defaultValue: 0 },
      status: { type: INTEGER, defaultValue: 1 },
      create_time: {
        type: DATE,
        get() {
          return dayjs(this.getDataValue('create_time')).format('YYYY-MM-DD HH:mm:ss');
        }
      },
      update_time: {
        type: DATE,
        get() {
          return dayjs(this.getDataValue('update_time')).format('YYYY-MM-DD HH:mm:ss');
        }
      }
    },
    {
      tableName: 'carousels',
      timestamps: true,
      createdAt: 'create_time',
      updatedAt: 'update_time'
    }
  );

  return Carousels;
};
